home *** CD-ROM | disk | FTP | other *** search
- /* fseek.c, from p. 434 of Turbo C Bible */
- #include <stdio.h>
- main()
- {
- FILE *infile;
- char filename[80], buffer[81];
- printf("enter name of a text file: ");
- gets(filename);
- /* Open the file for reading */
- if ((infile = fopen(filename, "r")) == NULL)
- {
- printf("fopen failed \n");
- exit(0);
- }
- /* Read and display a line */
- fgets(buffer, 80, infile);
- printf("Line read (before fseek): %s", buffer);
- /* Move to beginning using fseek and */
- /* read a line again */
- if (fseek(infile, 0L, SEEK_SET) != 0)
- {
- perror("fseek failed!");
- }
- else
- {
- fgets(buffer, 80, infile);
- printf("line read (after fseek) : %s", buffer);
- }
- }